/*YuO8szH0cVixePu/Bt+mG8hgu9A8tTONwNmuX8U41xc=*/
import { ajax, base, spaCache, toast } from 'nc-lightapp-front';
let { setDefData, getDefData } = spaCache;
import { pagecode, searchId, headId, bodyId, billType, dataSource, body_pkname } from '../constants';
import {sortFunction} from '../../../../public/components/pubUtils/billPubUtil'
import { onCheckedChange,getCheckedRowPK,updateCheckedRowsCurrentDealMny,updatePullMoney } from '../../../../public/components/transferTableSelectArea';

//点击查询，获取查询区数据
export default function () {
	let searchVal = this.props.search.getAllSearchData(searchId);
	if(searchVal && this.props.getUrlParam('dest_tradetype')){
		let data = {
			queryInfo: this.props.search.getQueryInfo(searchId),
			appcode: this.props.getUrlParam('src_appcode'),
			pageId: pagecode,
			src_billtype: billType,
			dest_tradetype: this.props.getUrlParam('dest_tradetype'),
			busitype: getDefData(billType + this.props.getUrlParam('src_tradetype'), "transfer.dataSource")
		}
		let generType = this.props.search.getSearchValByField(searchId, 'generationType');
		let checkedSum=0;
		//得到数据渲染到页面
		ajax({
			url: '/nccloud/arap/arappub/transferquery.do',
			data: data,
			success: (res) => {
				if( generType.value.firstvalue!=this.generationType){
					this.generationType =  generType.value.firstvalue;
					this.props.transferTable.clearAllSelectedData();
				}
				if (res.data) {
					let checkedRowPK=getCheckedRowPK.call(this,{headId, bodyId,body_pkname})||[];
					let newdata = res.data.sort(sortFunction('billdate','billno',headId));
					if(checkedRowPK&&checkedRowPK.length>0){
						let {resultData,pullMoney}=updateCheckedRowsCurrentDealMny.call(this,{checkedRowPK,data:newdata,headId, bodyId,body_pkname});
						newdata=resultData;
						checkedSum=pullMoney;
					}
					this.props.transferTable.setTransferTableValue(headId, bodyId, newdata, 'pk_recbill', 'pk_recitem');
					/*
					* key：存储数据的key
					* dataSource: 缓存数据命名空间
					* data： 存储数据
					*/
					setDefData('searchData', dataSource, res.data);
					toast({ color: 'success', content: this.state.json['receivablebill-000031']+res.data.length+this.state.json['receivablebill-000032'] });/* 国际化处理： 查询成功，共,条*/
				} else {
					this.props.transferTable.setTransferTableValue(headId, bodyId, [], 'pk_recbill', 'pk_recitem');								
					toast({ content: this.state.json['receivablebill-000063'], color: 'warning'});/* 国际化处理： 未查询到符合条件的数据*/
				}
				updatePullMoney.call(this,checkedSum);
				// onCheckedChange.call(this, null, null, null, null, {headId, bodyId, body_pkname});
			}
		})
	}
}

/*YuO8szH0cVixePu/Bt+mG8hgu9A8tTONwNmuX8U41xc=*/